package com.ruoyi.classroom.course.controller;


import com.ruoyi.classroom.course.domain.CourseManager;
import com.ruoyi.classroom.course.service.ICourseManagerService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 排课管理Controller
 * 
 * @author lgm
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/courseManager/courseManager")
public class CourseManagerController extends BaseController
{
    @Autowired
    private ICourseManagerService courseManagerService;

    /**
     * 查询排课管理列表
     */
    @RequiresPermissions("courseManager:courseManager:list")
    @GetMapping("/list")
    public TableDataInfo list(CourseManager courseManager)
    {
        startPage();
        List<CourseManager> list = courseManagerService.selectCourseManagerList(courseManager);
        return getDataTable(list);
    }

    /**
     * 一键排课
     * @param courseManager
     * @return
     */
    @RequiresPermissions("courseManager:courseManager:list")
    @GetMapping("/listOne")
    public TableDataInfo listOne(CourseManager courseManager)
    {
        startPage();

        List<CourseManager> list = courseManagerService.selectCourseManagerListOne(courseManager);
        return getDataTable(list);
    }

    /**
     * 导出排课管理列表
     */
    @RequiresPermissions("courseManager:courseManager:export")
    @Log(title = "排课管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseManager courseManager)
    {
        List<CourseManager> list = courseManagerService.selectCourseManagerList(courseManager);
        ExcelUtil<CourseManager> util = new ExcelUtil<CourseManager>(CourseManager.class);
        util.exportExcel(response, list, "排课管理数据");
    }

    /**
     * 获取排课管理详细信息
     */
    @RequiresPermissions("courseManager:courseManager:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseManagerService.selectCourseManagerById(id));
    }

    /**
     * 新增排课管理
     */
    @RequiresPermissions("courseManager:courseManager:add")
    @Log(title = "排课管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseManager courseManager)
    {
        return toAjax(courseManagerService.insertCourseManager(courseManager));
    }

    /**
     * 修改排课管理
     */
    @RequiresPermissions("courseManager:courseManager:edit")
    @Log(title = "排课管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseManager courseManager)
    {
        int result = courseManagerService.updateCourseManager(courseManager);
        if (result > 0) {
            return success();
        }else {
            return error("这个时间段已经有课程安排了！");
        }
    }

    /**
     * 删除排课管理
     */
    @RequiresPermissions("courseManager:courseManager:remove")
    @Log(title = "排课管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseManagerService.deleteCourseManagerByIds(ids));
    }
}
